package ar.com.sne.model.dao.geo;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import foundation.common.util.FinderFilter;
import foundation.common.util.PagedFinder;

import ar.com.sne.dao.GenericDAO;
import ar.com.sne.model.bo.geo.GeoTelefono;
import ar.com.sne.model.bo.geo.GeoTelefono;
import ar.com.sne.model.bo.per.PerPersona;

/**
 * DAO para el objeto del modelo: GeoTelefono.
 * @author Andrei
 */

public class GeoTelefonoDAO extends GenericDAO{

	public GeoTelefonoDAO() {
		super(GeoTelefono.class);
	}
	
	public GeoTelefonoDAO(Class boClass) {
		super(boClass);
	}

	private Logger log = Logger.getLogger(GeoTelefonoDAO.class);
	
	public PagedFinder findPaging(PagedFinder pf) {
		Criteria criteria =this.ListterFilter(pf.getFilter());		
		pf.setCount(super.getCount(criteria));
		criteria = this.ListterFilter(pf.getFilter());				
		criteria.setMaxResults(pf.getMaxResult());
		criteria.setFirstResult(pf.getFirstResult());
		pf.setResultList(criteria.list());		
		return pf;
	}
	
	private Criteria ListterFilter(FinderFilter filter){
		Criteria criteria = this.currentSession().createCriteria(GeoTelefono.class);
		
		PerPersona perPersona = (PerPersona)filter.getFilterValue("perPersona");
		if(perPersona != null){
			criteria.createAlias("perPersonas","perPersonas");
			criteria.add(Restrictions.eq("perPersonas.id", perPersona.getId()));
		}
		
		return criteria;
	}
	
	public List<GeoTelefono> findAll(){
		return this.getList();
	}
	
	public List<GeoTelefono> find(FinderFilter filter) {
		Criteria criteria =this.ListterFilter(filter);
		return criteria.list();
	}
}
